//
//  AGLoadingManager.m
//  AGLoadingView
//
//  Created by Aaron on 2018/4/22.
//  Copyright © 2018年 Aaron. All rights reserved.
//

#import "AGLoadingManager.h"
#import "AGLoadingView.h"
#import "AGLoadingChildView+Extension.h"

@interface AGLoadingManager ()

@property (nonatomic, strong) AGLoadingChildView *loadingView;


@end

static AGLoadingManager *_loadingManager = nil;

@implementation AGLoadingManager

+ (instancetype)shareLoadingManager {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _loadingManager = [[[self class] alloc] init];
    });
    return _loadingManager;
}

- (void)showLoadingViewIsAutoHidden:(BOOL)isAutoHidden {
    [[UIApplication sharedApplication].keyWindow addSubview:self.loadingView];
    if (isAutoHidden) {
        NSLog(@"系统加载视图自动隐藏\n");
    } else {
        NSLog(@"系统加载视图手动隐藏\n");
    }
}

- (void)hiddenLoadingView {
    [self.loadingView removeFromSuperview];
    NSLog(@"系统加载视图隐藏\n");
}

- (void)showCustomLoadingView:(UIView *)loadingView isAutoHidden:(BOOL)isAutoHidden {
    if (isAutoHidden) {
        NSLog(@"自定义加载视图自动隐藏\n");
    } else {
        NSLog(@"自定义加载视图手动隐藏\n");
    }
}

- (void)hiddenCustomLoadingView {
    NSLog(@"自定义加载视图隐藏\n");
}

- (void)hiddenAllLoadingView {
    NSLog(@"自定义和系统加载视图隐藏\n");
}


- (AGLoadingChildView *)loadingView {
    if (!_loadingView) {
        _loadingView = [[AGLoadingChildView alloc] initWithFrame:CGRectMake(50, 100, 200, 200)];
        _loadingView.backgroundColor = [UIColor blueColor];
    }
    return _loadingView;
}

@end
